package com.zygh.interactiveplatform.module.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.interactiveplatform.common.constant.EmployeeResponseCodeConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.CooperativeEnterprise;
import com.zygh.interactiveplatform.module.mapper.CooperativeEnterpriseMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lee
 * @since 2021-02-02
 */
@Service
public class CooperativeEnterpriseService extends ServiceImpl<CooperativeEnterpriseMapper, CooperativeEnterprise>{
    @Resource
    private CooperativeEnterpriseMapper cooperativeEnterpriseMapper;

    public ResponseDTO addCooperativeEnterprise(CooperativeEnterprise cooperativeEnterprise) {
        int insert = cooperativeEnterpriseMapper.insert(cooperativeEnterprise);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.ADD_EXIST);
    }

    public ResponseDTO updateCooperativeEnterprise(CooperativeEnterprise cooperativeEnterprise) {
        int insert = cooperativeEnterpriseMapper.updateById(cooperativeEnterprise);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.UPDATE_EXIST);
    }
    public ResponseDTO deleteCooperativeEnterprise(Integer id) {
        int insert = cooperativeEnterpriseMapper.deleteById(id);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.DELETE_EXIST);
    }
    public ResponseDTO findCooperativeEnterpriseAll(Integer current, Integer size) {
        PageHelper.startPage(current, size);
        List<CooperativeEnterprise> cooperativeEnterprises = cooperativeEnterpriseMapper.selectList(null);
        if (cooperativeEnterprises != null) {
            PageInfo<CooperativeEnterprise> pageInfo = new PageInfo<>(cooperativeEnterprises);
            return ResponseDTO.succData(pageInfo);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }
}
